<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>数据代理</title>
  </head>
  <body>
    <script>
      const vm = {
        _data: {
          name: "张三",
          age: 99,
        },
      };

      function dataBrokers(targetObj, proxyObj) {
        for (let key of Object.keys(targetObj)) {
          Object.defineProperty(proxyObj, key, {
            get() {
              return targetObj[key]
            },
            set(value) {
              return targetObj[key] = value
            },
          });
        }
      }

      dataBrokers(vm._data, vm)
    </script>
  </body>
</html>
